package com.academico.web.servlet.matricula;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.academico.dao.MatriculaDAO;
import com.academico.model.Matricula;
import com.academico.model.Matricula.SituacaoMatricula;
import com.academico.util.Util;
import com.academico.web.servlet.BaseServlet;

public class EditMatriculaServlet extends BaseServlet {

	private static final long serialVersionUID = 5096246529837899752L;

	@Override
	public void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		Integer raAluno = Util.convertStringToInteger(request.getParameter("raAluno"));
		Integer codigoCurso = Util.convertStringToInteger(request.getParameter("codigoCurso"));
		SituacaoMatricula situacaoMatricula = Matricula.SituacaoMatricula.valueOf(request.getParameter("situacaoMatricula"));
		
		Matricula matricula = new Matricula();
		matricula.setRaAluno(raAluno);
		matricula.setCodigoCurso(codigoCurso);
		matricula.setSituacaoMatricula(situacaoMatricula);
		
		MatriculaDAO matriculaDAO = new MatriculaDAO();
		matriculaDAO.update(matricula);
		setAttributeToRequest(request, "message", "Registro atualizado com sucesso");
		forward("matricula", request, response);

	}

}
